import { login } from '../../utils/request';

Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    callback: {
      type: Number,
      value: 0
    }
  },

  data: {
    appName: ''
  },

  ready() {
    this.setData({
      appName: wx.getStorageSync('navigation-bar-title')
    })
  },

  methods: {
    cancel () {
      this.setData({
        show: false
      })
    },

    confirm (event) {
      this.setData({ show: false })
      wx.showLoading({ title: '登录中...' })
      login().then(res => {
        const router = getCurrentPages()
        if (this.data.callback == 1) {
          router[router.length - 1].onLoad({})
        } else if (this.data.callback == 2) {
          router[router.length - 1].onShow()
        }
        wx.getLocation()
      })
      .catch(error => {
        console.log('Error:', error)
      })
        .finally(() => {
          wx.hideLoading()
        });
    }
  }
})